package example.com.zyfypt_618zgm.fragment;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.ImageButton;
import android.widget.TextView;
import android.widget.Toast;

import example.com.zyfypt_618zgm.R;
import example.com.zyfypt_618zgm.activity.CollectMain;
import example.com.zyfypt_618zgm.activity.Denglu;
import example.com.zyfypt_618zgm.activity.Focus;
import example.com.zyfypt_618zgm.model.LogoutModel;

/**
 * Created by 小茗同学 on 2017/6/1.
 */

public class MyFragment extends Fragment implements View.OnClickListener{
    private View view=null;
    private Context context;
    private ImageButton imageButton;
    private TextView username;
    private Button button5,button6;
    private String Session;
    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        view=inflater.inflate(R.layout.fragment1,container,false);
        context=getActivity();
        imageButton=(ImageButton)view.findViewById(R.id.imageButton);
        username=(TextView) view.findViewById(R.id.textView6);
        button5=(Button)view.findViewById(R.id.button5);
        button6=(Button)view.findViewById(R.id.button6);
        Session= Denglu.getSessionID();
        imageButton.setOnClickListener(this);
        button5.setOnClickListener(this);
        button6.setOnClickListener(this);
        username.setText(Denglu.getUsername());
        return view;
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.imageButton:
                new LogoutModel().getResult(Session);
                Toast.makeText(context, "注销成功", Toast.LENGTH_SHORT).show();
                getActivity().finish();
                break;
            case R.id.button5:
                Intent intent1=new Intent();
                intent1.setClass(context,Focus.class);
                startActivity(intent1);
                break;
            case R.id.button6:
                Intent intent2=new Intent();
                intent2.setClass(context,CollectMain.class);
                startActivity(intent2);
                break;
        }
    }
}
